package com.gitee.zhziyun.cnfsystem;

import java.net.*;

public class UDPClient {
    public static void main(String[] args) {
        try {
            // 创建UDP套接字
            DatagramSocket clientSocket = new DatagramSocket();

            // 创建要发送的数据
            String message = "Hello, UDP!";
            byte[] sendData = message.getBytes();

            // 指定服务器地址和端口
            InetAddress serverAddress = InetAddress.getByName("localhost");
            int serverPort = 8888;

            // 创建数据报
            DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, serverAddress, serverPort);

            // 发送数据报
            clientSocket.send(sendPacket);

            // 关闭UDP套接字
            clientSocket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
